<?php

// $Id$

require_once(TANGRA_MAIN_DIR.'form/gform_ctrl_with_obj.class.php');

require_once('image_form.class.php');
require_once('image_form_view.class.php');

require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/image/tcms_image_dbc.class.php');


class Image_Form_Ctrl extends GForm_Ctrl_With_Object {
	protected function create_form() {
		$form = new Image_Form();

//		$form->generate_html();
		return $form;
	}


	protected function create_form_view() {
		$ret = new Image_Form_View($this->form);

		return $ret;
	}


	protected function on_good_submit() {
		$ret = true;


		return $ret;
	}


	protected function on_bad_submit() {
		$content_id = $this->get_permanent_external_param('content', true);
		if ($content_id) {
			$this->export('image_cancel_link', 'admin/modules/tangra_cms/content_manage.php?manage='.$content_id);
		} else {
			$this->export('image_cancel_link', 'admin/modules/tangra_cms/image/images.php');
		}


		$dbc = $this->get_dbc();
		$object = $this->get_object();
		$object_id = $object->get_id();
		$image = new TCMS_Image_DBC();
		if ($image->load_by_id($dbc, $object_id)) {
			$this->export('orig_filename', $image->get_orig_filename());
		}
	}


	protected function create_object() {
		$object = new TCMS_Image_DBC();

		return $object;
	}


	protected function transfer_obj2form() {
		$object = $this->get_object();
		$form = $this->get_form();

		$form->set_field_value('note', $object->get_note());
		$form->set_field_value('alt', $object->get_alt());
	}


	protected function transfer_form2obj() {
		$object = $this->get_object();
		$form = $this->get_form();

		$object->set_note($form->get_field_value('note'));
		$object->set_alt($form->get_field_value('alt'));
	}
}